package com.per.mybootall.test;


import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: yyy
 * Date: 2021/12/4
 * Time: 9:16
 * Description:stream测试
 */
public class test02 {

    public static void main(String[] args) {
        List<Integer> rootList=new ArrayList<Integer>(){{
            add(1);add(2);add(3);add(4);add(5);add(6);add(7);add(8);add(9);add(10);
        }};
        List<Map> mapList=new ArrayList(){{
           add(new HashMap(){{put("name","Tom");put("age","20");}});
           add(new HashMap(){{put("name","Bob");put("age","19");}});
           add(new HashMap(){{put("name","Marly");put("age","18");}});
           add(new HashMap(){{put("name","YYY");put("age",new HashMap(){{put("smallAge",null);}});}});
        }};

        //IntStream.rangeClosed(0,4).map(x->x*x).forEach(System.out::println);


        //Stream.of("hello","world").map(s->s.split("")).forEach(System.out::println);
        //System.out.println("------------------------------");
        //Stream.of("hello","world").flatMap(s->Stream.of(s.split(""))).forEach(System.out::println);


      // List newList= rootList.stream().filter(str->str%2==1).collect(Collectors.toList());
      //    List newList= mapList.stream().filter(map->
      //    map.get("name").toString().equals("Tom")
      // ).collect(Collectors.toList());
       //newList.forEach(System.out::println);


       // String res= (String) Optional.ofNullable(mapList).map(hashMap->hashMap.get(3)).map(yyy->yyy.get("age")).orElse("这是null");
      //  System.out.println("---"+Optional.ofNullable(mapList).map(hashMap->hashMap.get(3)).map(yyy->yyy.get("age")).orElse("这是null"));

        rootList.forEach(System.out::println);
    }
}
